from time import time
import cv2
import numpy as np

from separate import Root_path


class CarIdentiy():
    def __init__(self) -> None:
        path =  Root_path+"changeNameTrain\\1.jpg"
        self.start(path)
        pass

    def start(self,path:str):
        gray_img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
        gray_img = cv2.resize(gray_img,(360,580))
        gauss_img = cv2.GaussianBlur(gray_img,(5,5),1)
        kernel = np.ones((23,23),np.uint8)
        open_operation = cv2.morphologyEx(gauss_img,cv2.MORPH_OPEN,kernel)
        _,threshold_img = cv2.threshold(open_operation,0,255,cv2.THRESH_OTSU+cv2.THRESH_BINARY)
        contours, hierarchy = cv2.findContours(threshold_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        for contour in contours:
            if cv2.contourArea( contour ) > 2000:
                # temp_contours.append(contour)
                print(contour)
        # cv2.drawContours(gray_img,contours,-1,(0,0,255),3)
        # self.show(gray_img)
    def show(self,img):
        cv2.imshow(str(time()),img)
        cv2.waitKey(0)


if __name__ == "__main__":
    carIdentiy =  CarIdentiy()
    